import { btnsModule } from '@renderer/utils/bundle'
import useMainStore from '@renderer/store/modules/useMainStore'
import { useWindowSize } from '@vueuse/core'
import useModalStore from '@renderer/store/modules/useModalStore'
import { getData } from '@renderer/store/modules/usePixiStore'
import { delDiyCard } from '@renderer/views/Card'
import * as PIXI from 'pixi.js'
// import { delCardClick } from '@renderer/utils/events'
import { createEf, Ef } from '@renderer/utils/ef'

const { width, height } = useWindowSize()
const modalStore = useModalStore()
// TODO 考虑合适的设计模式
const delCardClick = (): Ef => {
  return createEf(
    () => {
      if (modalStore.cardUid !== -1) {
        // TODO
        // const cardData = getData(modalStore.cardUid)
        // console.log(cardData)
        const cardData = getData(modalStore.cardUid)
        const cardContainer = cardData._convertContainer
        cardContainer.visible = false
        modalStore.setVisible(false)
        delDiyCard(cardData)
      }
    },
    {
      type: 'click',
      peimi: true,
    },
  )
}

export default async (): Promise<PIXI.Container<PIXI.ContainerChild>> => {
  const mainStore = useMainStore()
  const { scale } = mainStore.getAppAttr
  const container = new PIXI.Container()
  const sprite = await btnsModule('red')
  sprite.anchor.set(0.5)
  container.scale.set(0.6)
  container.addChild(sprite)
  container.position.set((width.value / scale) * 0.8 + container.width * 1.1, (height.value / scale) * 0.8 + container.height * 1.3)
  // 文字
  const text = new PIXI.Text({
    text: ' 删 除 ',
    alpha: 0.8,
    style: {
      fontFamily: 'RZFont',
      fontSize: 52,
      fill: 0x222222,
      align: 'center',
    },
  })
  text.anchor.set(0.5)
  container.addChild(text)
  delCardClick().whiteAdd(container)
  return container
}
